﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Shsc.Net.Common.Validator.Attributes;
using Shsc.Net.Common.Util;

namespace Shsc.Net.Common.Validator.Validators
{
    /// <summary>
    /// FixLengthCheck
    /// </summary>
    public class FixLengthValidator : BaseValidator
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <param name="attribute"></param>
        /// <returns></returns>
        public override bool DoValidate(object value, BaseValidationAttribute attribute)
        {
            FixLengthAttribute fixLengthAttribute = (FixLengthAttribute)attribute;
            bool bRet = true;
            if (fixLengthAttribute.IsByte)
            {
                bRet = CheckUtil.CheckFixByteLength(value, fixLengthAttribute.Length);
            }
            else
            {
                bRet = CheckUtil.CheckFixLength(value, fixLengthAttribute.Length);
            }
            return bRet;
        }
    }
}
